package com.nolon.flange.tools

import android.text.Editable
import android.text.TextWatcher

class TextWatcherFloat : TextWatcher {
    override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

    }

    override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

    }

    override fun afterTextChanged(s: Editable?) {
        val str = s?.toString() ?: return
        if (str.isEmpty()) return
        if (str[0] == '0') s.delete(0, 0)
        if (str.count { it == '.' } > 1) s.dropLast(1)
    }
}